package LeetCode.NumOffer;

public class NumOffer42 {
    public int maxSubArray(int[] nums) {
        if(nums.length == 0){
            return 0;
        }
        if(nums.length == 1){
            return nums[0];
        }
        int maxNum = -101;
        int midNum = nums[0];
        for (int x : nums) {
            midNum = Math.max(midNum + x, x);
            maxNum = Math.max(maxNum, midNum);
        }
        return maxNum;
    }
}
